/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package applet.source.action;

import applet.visualisation.VisuApp;
import java.awt.event.MouseEvent;
import java.util.Iterator;
import prefuse.controls.ControlAdapter;
import prefuse.data.Tree;
import prefuse.visual.EdgeItem;
import prefuse.visual.NodeItem;
import prefuse.visual.VisualItem;

/**
 *
 * @author krishen
 */
public class FindMaxDepth extends ControlAdapter{

     public void itemClicked(VisualItem item, MouseEvent e) {

          if ( item instanceof NodeItem ){
            determineProfondeurnoeuds((NodeItem)item);

          }

    }

     

     private void determineProfondeurnoeuds(NodeItem n){

        //VisuApp.fsim.getForces()[0].setParameter(0, 0);
      

       int maxDepth = 0;
       Object obj = null;

       //prefuse.data.Tree.m_root = n.getRow();

       Iterator tuples = n.getGraph().tuples();
       while (tuples.hasNext() )
       {
           obj = tuples.next();
           if (obj instanceof prefuse.data.Node) {
              n = (NodeItem)obj;
              //n.setSize(1);
              maxDepth =  Math.max(maxDepth, n.getDepth());

           }

        }

       tuples = n.getGraph().tuples();
       while (tuples.hasNext() )
       {
           obj = tuples.next();
           if (obj instanceof prefuse.data.Node) {
              n = (NodeItem)obj;
              if (n.getDepth() == maxDepth){
                  n.setSize(2);
              }
           }

       }

       VisuApp.jTable1.getModel().setValueAt(maxDepth, 3, 1);
       //VisuApp.jTable1.getModel().setValueAt(prefuse.data.Tree.m_root, 4, 1);
         
        
     }



      public void itemExited(VisualItem item, MouseEvent e) {

          if ( item instanceof NodeItem ){

                NodeItem n = (NodeItem) item;
                Object obj = null;
                Iterator tuples = n.getGraph().tuples();
                while (tuples.hasNext() )
                {
                   obj = tuples.next();
                   if (obj instanceof prefuse.data.Node) {
                       n = (NodeItem)obj;
                       n.setSize(1);
                       
                   }
                 }
           }
        }

    

}
